﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocumentStorage.EFRepository.Interfaces;
using DocumentStorage.Models;
using DocumentStorage.Services;
using DocumentStorage.Services.Interfaces;
using Moq;
using NBehave.Spec.NUnit;
using NUnit.Framework;

namespace DocumentStorage.UnitTests.DocumentService
{
  public class when_working_with_the_document_service : Specification
  {
    protected Mock<IDocumentRepository> _documentRepository;
    protected IDocumentPersistanceService _documentService;

    protected override void Establish_context()
    {
      base.Establish_context();

      _documentRepository = new Mock<IDocumentRepository>();
      _documentService = new Services.Services.DocumentPersistanceService(_documentRepository.Object);
    }
  }

  public class and_creating_a_valid_document : when_working_with_the_document_service
  {
    private Document _testDocument;
    private Exception _result;

    protected override void Establish_context()
    {
      base.Establish_context();

      _documentRepository.Setup(d => d.Create(It.IsAny<Document>()));
    }

    protected override void Because_of()
    {
      try
      {
        _documentService.CreateDocument(_testDocument);
      }
      catch (Exception exception)
      {
        _result = exception;
      }
    }

    [Test]
    public void then_a_valid_document_id_should_be_returned()
    {
      _result.ShouldBeNull();
    }
  }

  public class and_creating_an_invalid_document : when_working_with_the_document_service
  {
    private Exception _result;

    protected override void Establish_context()
    {
      base.Establish_context();

      _documentRepository.Setup(d => d.Create(null)).Throws(new ArgumentNullException());
    }

    protected override void Because_of()
    {
      base.Because_of();

      try
      {
        _documentService.CreateDocument(null);
      }
      catch (Exception exception)
      {
        _result = exception;
      }
    }

    [Test]
    public void then_an_argument_null_exception_should_be_raised()
    {
      _result.ShouldBeInstanceOfType(typeof(ArgumentNullException));
    }
  }

  public class and_creating_a_document_with_content : when_working_with_the_document_service
  {


  }
}
